#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
struct students
{
	int sex;
	string name;
	int i;
};
int main()
{
	int n;
	cin >> n;
	students *stus = new students[n];
	for (int i = 0; i < n; i++)
	{
		cin >> stus[i].sex >> stus[i].name;
		stus[i].i = 1;
	}
	for (int i = 0; i < n / 2; i++)
	{
		for (int j = n - 1; j >= n / 2; j--)
		{
			if (stus[i].sex != stus[j].sex && stus[i].i == 1 && stus[j].i == 1)
			{
				cout << stus[i].name << " " << stus[j].name << endl;
				stus[i].i = stus[j].i = 0;
			}
		}
	}

	system("PAUSE");
	return 0;
}